package com.xzq.bugstack;

import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.socket.SocketChannel;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author xzq
 * @Description //TODO
 * @Date 2021/11/19 10:30
 * @Version 1.0.0
 **/
public class MyServerHandler extends ChannelInboundHandlerAdapter {
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        SocketChannel channel = (SocketChannel) ctx.channel();
        System.out.println("连接建立...");
        System.out.println("连接IP: "+channel.localAddress().getHostString());
        System.out.println("连接端口: " + channel.localAddress().getPort());
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        //接受msg消息，这里已经不需要自己进行解码
        System.out.println(new SimpleDateFormat("yyyy-MM-dd Hh:mm:ss").format(new Date()  )+"接收到信息： " + msg);
    }
}
